package com.cj.core.common;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: FileTypeUtils
 * Description:
 *
 * @author chenjun
 * @date: 2024/11/4 11:33
 */
public class FileUtils {

    public static String getFileType(String mimeType) {
        // 定义 MIME 类型到文件类型标识符的映射
        final Map<String, String> mappings = new HashMap<>();
        // 图片
        mappings.put("image/jpeg", "image");
        mappings.put("image/png", "image");
        mappings.put("image/gif", "image");
        mappings.put("image/svg+xml", "image");
        mappings.put("image/webp", "image");
        mappings.put("image/bmp", "image");
        mappings.put("image/tiff", "image");
        // 视频
        mappings.put("video/mp4", "video");
        mappings.put("video/x-msvideo", "video");
        mappings.put("video/quicktime", "video");
        mappings.put("video/x-matroska", "video");
        mappings.put("video/avi", "video");
        // 音频
        mappings.put("audio/mpeg", "audio");
        mappings.put("audio/x-wav", "audio");
        mappings.put("audio/x-aiff", "audio");
        // Word 文档
        mappings.put("application/msword", "word");
        mappings.put("application/vnd.openxmlformats-officedocument.wordprocessingml.document", "word");
        // Excel 文档
        mappings.put("application/vnd.ms-excel", "table");
        mappings.put("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "table");
        mappings.put("text/csv", "table");
        mappings.put("application/csv", "table");
        // PDF
        mappings.put("application/pdf", "pdf");
        // PowerPoint 文档
        mappings.put("application/vnd.ms-powerpoint", "ppt");
        mappings.put("application/vnd.openxmlformats-officedocument.presentationml.presentation", "ppt");
        // 文本文件
        mappings.put("text/plain", "txt");
        // 脚本和编程语言文件
        mappings.put("application/javascript", "js");
        mappings.put("application/json", "json");
        mappings.put("application/xml", "xml");
        mappings.put("text/html", "html");
        mappings.put("application/x-sql", "sql");
        mappings.put("text/x-markdown", "md");
        // 压缩文件
        mappings.put("application/zip", "zip");
        mappings.put("application/x-rar-compressed", "rar");
        mappings.put("application/x-tar", "tar");
        mappings.put("application/x-7z-compressed", "7z");
        // 其他文件类型
        mappings.put("application/octet-stream", "binary");
        // 返回对应的文件类型标
        return mappings.getOrDefault(mimeType, "other");
    }
}
